package student.stu23002129.chapter13.UDPThread;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class TestSend  extends Thread{
    public void run() {
        try {
            DatagramSocket socket = new DatagramSocket();//创建socket相当于创建码头
            Scanner sc = new Scanner(System.in);
            while(true) {
                String str = sc.nextLine();
                if("quit".equals(str))
                    break;
                DatagramPacket packet = new DatagramPacket(str.getBytes(),
                        str.getBytes().length, InetAddress.getByName("127.0.0.1"), 6666);
                socket.send(packet);//发货
            }
            socket.close();
        }  catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new teacher.chapter13.UDPThread.TestSend().run();
        return;
    }

}
